package com.springboot.example.web.interceptor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * spring-boot AOP演示
 * <p/>
 * 作者: guo yao
 * 日期: 2016年01月15日
 * 时间: 下午17:02
 */

@Aspect
@Component
public class AspectInterceptor {

    @Pointcut("execution(public * com.springboot.example.web.web..*(..))")
    public void recordLog() {
    }

    /*@Around("execution(* com.springboot.example.web.web..*(..))")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable{
        System.out.println("into interceptor");
        // 业务处理
//        for (Object obj : joinPoint.getArgs()) {

//        }
        joinPoint.proceed();
        System.out.println("return");
    }*/


//    @Around("recordLog()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("into interceptor");
        // 业务处理
       /* for (Object obj : joinPoint.getArgs()) {

        }*/

        System.out.println("return around");
        try {
            System.out.println("iniinnin");
        } catch (Exception e){
            e.printStackTrace();
        } finally {
            joinPoint.proceed();
        }

    }

    @AfterReturning("recordLog()")
    public void logServiceAccess(JoinPoint joinPoint) {
        System.out.println("Completed: " + joinPoint);
    }
}
